//本地数据库 
var storage = window.localStorage;  

/**
 * 登录保存
 * @returns {Boolean}
 */
function login() {
		var logonNam=$("#logonNam").val();
		var password=$("#password").val();
		
		if(logonNam==null || logonNam==''){
			alert('用户名不能为空');
			return false;
		}
		if(password==null || password==''){
			alert('密码不能为空');
			return false;
		}
		var url =_global.serverHost +"/consignerRegisterAndLogin/loginValide.htm";
	    $.ajax({
			type: "POST",
			url:  url,
			async : false, // 使用同步方式
			crossDomain : true,
			dataType : "json",
			data: $('#consignerForm').serialize(),
			contentType:"application/x-www-form-urlencoded;charset=UTF-8",
			success : function(data) {
				//console.log("======"+data);
				 if(data.outResult=="1"){
					 setCookie("customerUuid",data.token);
					 //console.log("=="+window.location.href);
					 window.location.href=_global.custIndexUrl+"?sourceFrom=LOGIN";
				}else{
					alert(data.outResultReason);
				}
			},
			error : function(err) {
				alert(JSON.stringify(err));
			}
		});
	}


function myOrder(){
	 window.location.href=_global.serverHost +"/consignerOrderManger/orderList.htm";
}

function order2Cookie(){
	var tmpValue=document.getElementsByName("vehiclePriceId")[0].value;
	setCookie('vehiclePriceId',tmpValue);
	
	tmpValue=document.getElementsByName("bookDate")[0].value;
	setCookie('bookDate',tmpValue);
	
	tmpValue=document.getElementsByName("consignDesc")[0].value;
	setCookie('consignDesc',tmpValue);
	
	tmpValue=document.getElementsByName("callType")[0].value;
	setCookie('callType',tmpValue);
	
	tmpValue=document.getElementsByName("addrType")[0].value;
	setCookie('addrType',tmpValue);
	
	tmpValue=document.getElementsByName("waybillRquirement10")[0].value;
	setCookie('waybillRquirement10',tmpValue);
	
	tmpValue=document.getElementsByName("waybillRquirement20")[0].value;
	setCookie('waybillRquirement20',tmpValue);
	
	tmpValue=document.getElementsByName("waybillRquirement30")[0].value;
	setCookie('waybillRquirement30',tmpValue);
	
	
	
	tmpValue=document.getElementsByName("startDistrictCode")[0].value;
	setCookie('startDistrictCode',tmpValue);
	
	//tmpValue=document.getElementsByName("startAddr")[0].value;
	tmpValue=$("#startAddr").val();
	setCookie('startAddr',tmpValue);
	tmpValue=document.getElementsByName("startPCD")[0].value;
	setCookie('startPCD',tmpValue);
	
	tmpValue=document.getElementsByName("startLocation")[0].value;
	setCookie('startLocation',tmpValue);
	
	tmpValue=document.getElementsByName("endDistrictCode")[0].value;
	setCookie('endDistrictCode',tmpValue);
	
	tmpValue=document.getElementsByName("endAddr")[0].value;
	setCookie('endAddr',tmpValue);
	
	tmpValue=document.getElementsByName("endPCD")[0].value;
	setCookie('endPCD',tmpValue);
	tmpValue=document.getElementsByName("endLocation")[0].value;
	setCookie('endLocation',tmpValue);
	tmpValue=document.getElementsByName("vehiclePriceId")[0].value;
	setCookie('vehiclePriceId',tmpValue);
	tmpValue=document.getElementsByName("endDistrictCode1")[0].value;
	setCookie('endDistrictCode1',tmpValue);
	tmpValue=document.getElementsByName("endAddr1")[0].value;
	setCookie('endAddr1',tmpValue);
	tmpValue=document.getElementsByName("endPCD1")[0].value;
	setCookie('endPCD1',tmpValue);
	tmpValue=document.getElementsByName("endLocation1")[0].value;
	setCookie('endLocation1',tmpValue);
	tmpValue=document.getElementsByName("endDistrictCode2")[0].value;
	setCookie('endDistrictCode2',tmpValue);
	tmpValue=document.getElementsByName("endAddr2")[0].value;
	setCookie('endAddr2',tmpValue);
	
	tmpValue=document.getElementsByName("endLocation2")[0].value;
	setCookie('endLocation2',tmpValue);
	tmpValue=document.getElementsByName("endPCD2")[0].value;
	setCookie('endPCD2',tmpValue);
	tmpValue=document.getElementsByName("goodsRemark")[0].value;
	setCookie('goodsRemark',tmpValue);
	tmpValue=document.getElementsByName("goodsType")[0].value;
	setCookie('goodsType',tmpValue);
	tmpValue=document.getElementsByName("goodsTypeName")[0].value;
	setCookie('goodsTypeName',tmpValue);
	tmpValue=document.getElementsByName("consignNum")[0].value;
	setCookie('consignNum',tmpValue);
	tmpValue=document.getElementsByName("endAddrCount")[0].value;
	setCookie('endAddrCount',tmpValue);
	tmpValue=document.getElementsByName("startStreet")[0].value;
	setCookie('startStreet',tmpValue);
	tmpValue=document.getElementsByName("startCross")[0].value;
	setCookie('startCross',tmpValue);
	tmpValue=document.getElementsByName("startDoorNo")[0].value;
	setCookie('startDoorNo',tmpValue);
	tmpValue=document.getElementsByName("consignMobile")[0].value;
	setCookie('consignMobile',tmpValue);
	tmpValue=document.getElementsByName("consignName")[0].value;
	setCookie('consignName',tmpValue);
	
	tmpValue=document.getElementsByName("endStreet")[0].value;
	setCookie('endStreet',tmpValue);
	tmpValue=document.getElementsByName("endCross")[0].value;
	setCookie('endCross',tmpValue);
	tmpValue=document.getElementsByName("endDoorNo")[0].value;
	setCookie('endDoorNo',tmpValue);
	tmpValue=document.getElementsByName("acceptPersonMobile")[0].value;
	setCookie('acceptPersonMobile',tmpValue);
	tmpValue=document.getElementsByName("acceptPersonName")[0].value;
	setCookie('acceptPersonName',tmpValue);
	
	tmpValue=document.getElementsByName("endStreet1")[0].value;
	setCookie('endStreet1',tmpValue);
	tmpValue=document.getElementsByName("endCross1")[0].value;
	setCookie('endCross1',tmpValue);
	tmpValue=document.getElementsByName("endDoorNo1")[0].value;
	setCookie('endDoorNo1',tmpValue);
	tmpValue=document.getElementsByName("acceptPersonMobile1")[0].value;
	setCookie('acceptPersonMobile1',tmpValue);
	tmpValue=document.getElementsByName("acceptPersonName1")[0].value;
	setCookie('acceptPersonName1',tmpValue);
	
	tmpValue=document.getElementsByName("endStreet2")[0].value;
	setCookie('endStreet2',tmpValue);
	tmpValue=document.getElementsByName("endCross2")[0].value;
	setCookie('endCross2',tmpValue);
	tmpValue=document.getElementsByName("endDoorNo2")[0].value;
	setCookie('endDoorNo2',tmpValue);
	tmpValue=document.getElementsByName("acceptPersonMobile2")[0].value;
	setCookie('acceptPersonMobile2',tmpValue);
	tmpValue=document.getElementsByName("acceptPersonName2")[0].value;
	setCookie('acceptPersonName2',tmpValue);
	
	tmpValue=document.getElementsByName("planLoadTime")[0].value;
	setCookie('planLoadTime',tmpValue);
	tmpValue=document.getElementsByName("planUnloadTime")[0].value;
	setCookie('planUnloadTime',tmpValue);
	tmpValue=document.getElementsByName("planLoadFee")[0].value;
	setCookie('planLoadFee',tmpValue);
	tmpValue=document.getElementsByName("planUnloadFee")[0].value;
	setCookie('planUnloadFee',tmpValue);
	tmpValue=document.getElementsByName("planLowSpeedTime")[0].value;
	setCookie('planLowSpeedTime',tmpValue);
	tmpValue=document.getElementsByName("planLowSpeedFee")[0].value;
	setCookie('planLowSpeedFee',tmpValue);
	
	
}

/**
 * 清空订单cookie
 */
function clearOrderCookie(){
	var tmpValue='';
	setCookie('vehiclePriceId',tmpValue);
	
	setCookie('bookDate',tmpValue);
	
	setCookie('consignDesc',tmpValue);
	
	setCookie('callType',tmpValue);
	
	setCookie('addrType',tmpValue);
	
	setCookie('waybillRquirement10',tmpValue);
	
	setCookie('waybillRquirement20',tmpValue);
	
	setCookie('waybillRquirement30',tmpValue);
	
	setCookie('startDistrictCode',tmpValue);
	
	setCookie('startAddr',tmpValue);
	setCookie('startPCD',tmpValue);
	
	setCookie('startLocation',tmpValue);
	
	setCookie('endDistrictCode',tmpValue);
	
	setCookie('endAddr',tmpValue);
	
	setCookie('endPCD',tmpValue);
	setCookie('endLocation',tmpValue);
	setCookie('vehiclePriceId',tmpValue);
	setCookie('endDistrictCode1',tmpValue);
	setCookie('endAddr1',tmpValue);
	setCookie('endPCD1',tmpValue);
	setCookie('endLocation1',tmpValue);
	setCookie('endDistrictCode2',tmpValue);
	setCookie('endAddr2',tmpValue);
	
	setCookie('endLocation2',tmpValue);
	setCookie('endPCD2',tmpValue);
	setCookie('goodsRemark',tmpValue);
	setCookie('goodsType',tmpValue);
	setCookie('goodsTypeName',tmpValue);
	setCookie('consignNum',tmpValue);
	setCookie('endAddrCount',tmpValue);
	
	setCookie('startStreet',tmpValue);
	setCookie('startCross',tmpValue);
	setCookie('startDoorNo',tmpValue);
	setCookie('consignMobile',tmpValue);
	setCookie('consignName',tmpValue);
	
	setCookie('endStreet',tmpValue);
	setCookie('endCross',tmpValue);
	setCookie('endDoorNo',tmpValue);
	setCookie('acceptPersonMobile',tmpValue);
	setCookie('acceptPersonName',tmpValue);
	
	setCookie('endStreet1',tmpValue);
	setCookie('endCross1',tmpValue);
	setCookie('endDoorNo1',tmpValue);
	setCookie('acceptPersonMobile1',tmpValue);
	setCookie('acceptPersonName1',tmpValue);
	
	setCookie('endStreet2',tmpValue);
	setCookie('endCross2',tmpValue);
	setCookie('endDoorNo2',tmpValue);
	setCookie('acceptPersonMobile2',tmpValue);
	setCookie('acceptPersonName2',tmpValue);
	
	setCookie('planLoadTime',tmpValue);
	setCookie('planUnloadTime',tmpValue);
	setCookie('planLoadFee',tmpValue);
	setCookie('planUnloadFee',tmpValue);
	setCookie('planLowSpeedTime',tmpValue);
	setCookie('planLowSpeedFee',tmpValue);
}

/**
 * cookie信息给订单
 */
function cookie2Order(){
	var tmpValue=getCookie("vehiclePriceId");
	$("#vehiclePriceId").val(tmpValue);
	var tmpValue=getCookie("bookDate");
	$("#bookDate").val(tmpValue);
	var tmpValue=getCookie("consignDesc");
	$("#consignDesc").val(tmpValue);
	var tmpValue=getCookie("callType");
	$("#callType").val(tmpValue);
	var tmpValue=getCookie("addrType");
	$("#addrType").val(tmpValue);
	var tmpValue=getCookie("waybillRquirement10");
	$("#waybillRquirement10").val(tmpValue);
	var tmpValue=getCookie("waybillRquirement20");
	$("#waybillRquirement20").val(tmpValue);
	var tmpValue=getCookie("waybillRquirement30");
	$("#waybillRquirement30").val(tmpValue);
	var tmpValue=getCookie("startDistrictCode");
	$("#startDistrictCode").val(tmpValue);
	var tmpValue=getCookie("startAddr");
	$("#startAddr").val(tmpValue);
	var tmpValue=getCookie("startPCD");
	$("#startPCD").val(tmpValue);
	var tmpValue=getCookie("startLocation");
	$("#startLocation").val(tmpValue);
	var tmpValue=getCookie("endDistrictCode");
	$("#endDistrictCode").val(tmpValue);
	var tmpValue=getCookie("endAddr");
	$("#endAddr").val(tmpValue);
	var tmpValue=getCookie("endPCD");
	$("#endPCD").val(tmpValue);
	var tmpValue=getCookie("endLocation");
	$("#endLocation").val(tmpValue);
	var tmpValue=getCookie("endDistrictCode1");
	$("#endDistrictCode1").val(tmpValue);
	var tmpValue=getCookie("endAddr1");
	$("#endAddr1").val(tmpValue);
	var tmpValue=getCookie("endPCD1");
	$("#endPCD1").val(tmpValue);
	var tmpValue=getCookie("endLocation1");
	$("#endLocation1").val(tmpValue);
	var tmpValue=getCookie("endDistrictCode2");
	$("#endDistrictCode2").val(tmpValue);
	var tmpValue=getCookie("endAddr2");
	$("#endAddr2").val(tmpValue);
	var tmpValue=getCookie("endPCD2");
	$("#endPCD2").val(tmpValue);
	var tmpValue=getCookie("endLocation2");
	$("#endLocation2").val(tmpValue);
	var tmpValue=getCookie("goodsRemark");
	$("#goodsRemark").val(tmpValue);
	var tmpValue=getCookie("goodsType");
	$("#goodsType").val(tmpValue);
	var tmpValue=getCookie("goodsTypeName");
	$("#goodsTypeName").val(tmpValue);
	var tmpValue=getCookie("consignNum");
	$("#consignNum").val(tmpValue);
	var tmpValue=getCookie("endAddrCount");
	$("#endAddrCount").val(tmpValue);
	 tmpValue=getCookie("customerUuid");
	$("#customerUuid").val(tmpValue);
	
	 tmpValue=getCookie("startStreet");
	$("#startStreet").val(tmpValue);
	tmpValue=getCookie("startCross");
	$("#startCross").val(tmpValue);
	tmpValue=getCookie("startDoorNo");
	$("#startDoorNo").val(tmpValue);
	tmpValue=getCookie("consignMobile");
	$("#consignMobile").val(tmpValue);
	tmpValue=getCookie("consignName");
	$("#consignName").val(tmpValue);
	
	tmpValue=getCookie("endStreet");
	$("#endStreet").val(tmpValue);
	tmpValue=getCookie("endCross");
	$("#endCross").val(tmpValue);
	tmpValue=getCookie("endDoorNo");
	$("#endDoorNo").val(tmpValue);
	tmpValue=getCookie("acceptPersonMobile");
	$("#acceptPersonMobile").val(tmpValue);
	tmpValue=getCookie("acceptPersonName");
	$("#acceptPersonName").val(tmpValue);
	
	tmpValue=getCookie("endStreet1");
	$("#endStreet1").val(tmpValue);
	tmpValue=getCookie("endCross1");
	$("#endCross1").val(tmpValue);
	tmpValue=getCookie("endDoorNo1");
	$("#endDoorNo1").val(tmpValue);
	tmpValue=getCookie("acceptPersonMobile1");
	$("#acceptPersonMobile1").val(tmpValue);
	tmpValue=getCookie("acceptPersonName1");
	$("#acceptPersonName1").val(tmpValue);
	
	tmpValue=getCookie("endStreet2");
	$("#endStreet2").val(tmpValue);
	tmpValue=getCookie("endCross2");
	$("#endCross2").val(tmpValue);
	tmpValue=getCookie("endDoorNo2");
	$("#endDoorNo2").val(tmpValue);
	tmpValue=getCookie("acceptPersonMobile2");
	$("#acceptPersonMobile2").val(tmpValue);
	tmpValue=getCookie("acceptPersonName2");
	$("#acceptPersonName2").val(tmpValue);
	
	tmpValue=getCookie("planLoadTime");
	$("#planLoadTime").val(tmpValue);
	tmpValue=getCookie("planUnloadTime");
	$("#planUnloadTime").val(tmpValue);
	tmpValue=getCookie("planLoadFee");
	$("#planLoadFee").val(tmpValue);
	tmpValue=getCookie("planUnloadFee");
	$("#planUnloadFee").val(tmpValue);
	tmpValue=getCookie("planLowSpeedTime");
	$("#planLowSpeedTime").val(tmpValue);
	tmpValue=getCookie("planLowSpeedFee");
	$("#planLowSpeedFee").val(tmpValue);
	
}


function setCookie(name,value)  
{  
	//localStorage.setItem(name,value);
	try{
		delegate.setCookie(name,value);
	}catch(e){
			alert(e);
	}
	/*var Days = 0.1;
	var exp = new Date();
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();*/
}  
function getCookie(name)  
{  
	
	//var  nameValue=localStorage.getItem(name);
	var  nameValue=localStorage.getItem(name);
	try{
		nameValue=delegate.getCookie(name);
	}catch(e){
			alert(e);
	}
   /* var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");  
    if(arr=document.cookie.match(reg))  
        return (unescape(arr[2]));  
    else  
        return null;  */
	if(nameValue==undefined){
		nameValue=null;
	}
	return nameValue;
}  

function delCookie(name)  
{  
	localStorage.removeItem(name);
   /* var exp = new Date();  
    exp.setTime(exp.getTime() - 1);  
    var cval=getCookie(name);  
    if(cval!=null)  
        document.cookie= name + "="+cval+";expires="+exp.toGMTString();  */
}  

function checkToken(){
	var customerUuid=getCookie("customerUuid");
	if(customerUuid==undefined || customerUuid==null || customerUuid==''){
		window.location.href='../'+_global.custLoginUrl;
	}else{
		 $.ajax({
	         type: 'POST',
	         url: _global.serverHost + '/consignerRegisterAndLogin/validToken.htm',
	         dataType: "json",
	         data: { 'customerUuid': customerUuid},
	         success: function (data) {
	        	
	             if (data.outResult == '1') {
	            	 return '1';
	             } else {
	            	 window.location.href='../'+_global.custLoginUrl;
	             }
	         }
	     });
		
	}
	
}

function checkTokenIndex(){
	var customerUuid=getCookie("customerUuid");
	console.log("===="+customerUuid);
	if(customerUuid==undefined || customerUuid==null || customerUuid==''){
		window.location.href=_global.custLoginUrl;
	}else{
		 $.ajax({
	         type: 'POST',
	         url: _global.serverHost + '/consignerRegisterAndLogin/validToken.htm',
	         dataType: "json",
	         data: { 'customerUuid': customerUuid},
	         success: function (data) {
	        	
	             if (data.outResult == '1') {
	            	 return '1';
	             } else {
	            	 window.location.href= _global.custLoginUrl;
	             }
	         }
	     });
		
	}
	
}